package com.yx.changdao.common.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.yx.changdao.common.annotation.AutoFill;
import lombok.Getter;
import lombok.Setter;
import org.apache.ibatis.annotations.Select;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Description: <br />
 * 系统菜单实体
 * <p>
 * <br />
 * @Auther: Zhangjiashun
 * @create 2019/11/15 17:01
 */

@Getter
@Setter

@TableName(SysMenu.TABLE_NAME)
public class SysMenu implements Cloneable, Serializable {
    private static final long serialVersionUID = 1L;
    public static final String TABLE_NAME = "sys_menu";
    /**
     * 菜单id
     */
    public static final String MENU_ID = "menu_id";
    /**
     * 菜单名称
     */
    public static final String MENU_NAME = "menu_name";
    /**
     * 菜单链接
     */
    public static final String MENU_URI = "menu_uri";
    /**
     * 菜单父级
     */
    public static final String MENU_PARENT = "menu_parent";
    /**
     * 菜单图标
     */
    public static final String MENU_ICON = "menu_icon";
    /**
     * 菜单顺序
     */
    public static final String MENU_SORT = "menu_sort";
    /**
     * 权限id
     */
    public static final String PERMISSION_ID = "permission_id";
    /**
     * 创建时间
     */
    public static final String CREATE_TIME = "create_time";

    /**
     * 页面存放的真实位置
     */
    public static final String MENU_FILE = "menu_file";

    @TableId(type = IdType.ASSIGN_ID)
    private String menuId;
    @NotEmpty(message = "菜单名称不能为空")
    @Length(min = 1, max = 32, message = "菜单名称只能在1~32位之间")
    private String menuName;
    private String menuUri;
    @Length(min = 1, max = 32, message = "父级菜单只能在1~32位之间")
    private String menuParent;
    @Length(min = 1, max = 32, message = "菜单图标只能在1~32位之间")
    private String menuIcon;
    private int menuSort;
    @Length(min = 1, max = 32, message = "权限id只能在1~32位之间")
    private String permissionId;

    private String menuFile; //页面存放地址


    @AutoFill
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;


    @TableField(exist = false)
    private List<SysMenu> subMenu;

    public SysMenu() {
        this.subMenu = new ArrayList<>();
    }


    @Override
    public boolean equals(Object obj) {
        if (obj instanceof SysMenu) {
            return this.getMenuId().equals(((SysMenu) obj).getMenuId());
        }
        return false;
    }

    @Override
    public SysMenu clone() {
        try {
            return (SysMenu) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.menuId, this.menuName, this.menuUri, this.menuParent, this.menuIcon, this.menuSort, this.permissionId, this.createTime, this.subMenu);
    }
}
